package org.vectrics.recruiter.struts.admin.person;

import javax.servlet.jsp.JspException;

import org.vectrics.cv.University;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.struts.VectricsActionData;
import org.vectrics.struts.VectricsStrutsAction;

/**
 * @author pgoette
 * Clase Action encargada de guardar una Universidad
 */
public class SaveUniversityAction extends VectricsStrutsAction {

	@Override
	protected String doExecute(VectricsActionData actionData)
			throws JspException {
		
		String forward = "success";
		UniversityForm form = (UniversityForm) actionData.getForm();
		University university = null;		
		
		if (actionData.wasButtonPressed("cancel")) {
			return forward;
		}
		
		if ((form.getId() == null)||(form.getId().trim().equals(""))) {
			university = new University();
		} else {
			university = RecruitServiceLocator.getPersonService().findUniversity(new Long(form.getId()));
		}
		
		university.setName(form.getName());
		RecruitServiceLocator.getPersonService().saveUniversity(university);
		
		return forward;
	}

}
